package com.suning.sawp.service.impl.logistics;

import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.base.Function;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.suning.rsc.dto.responsedto.MbfResponse;
import com.suning.rsc.httpservice.annotation.EsbEIHttpWired;
import com.suning.sawp.dto.esb.CStoreLogisticsQueryReq;
import com.suning.sawp.dto.esb.CStoreLogisticsQueryReq.CStoreLogisticsQueryDetail;
import com.suning.sawp.dto.esb.CStoreLogisticsQueryResp;
import com.suning.sawp.dto.esb.CStoreLogisticsQueryResp.CStoreLogisticsDetail;
import com.suning.sawp.dto.esb.LogisticsQueryReq;
import com.suning.sawp.dto.esb.LogisticsQueryResp;
import com.suning.sawp.dto.esb.LogisticsQueryResp.LogisticsDetail;
import com.suning.sawp.dto.esb.OmsOrderDetailResp;
import com.suning.sawp.dto.esb.OmsOrderDetailResp.OmsOrderList;
import com.suning.sawp.dto.esb.OmsOrderDetailResp.OmsOrderbodyList;
import com.suning.sawp.dto.logistics.LogisticsDetailDto;
import com.suning.sawp.dto.logistics.LogisticsDto;
import com.suning.sawp.dto.yxwt.LogisticsReq;
import com.suning.sawp.intf.esb.CStoreLogisticsESBService;
import com.suning.sawp.intf.esb.LogisticsESBService;
import com.suning.sawp.intf.esb.OmsOrderDetailService;
import com.suning.sawp.intf.logistics.LogisticsService;
import com.suning.sawp.service.util.BaseContants;
import com.suning.sawp.service.util.DJStringUtils;
import com.suning.sawp.service.util.DateUtils;
import com.suning.sawp.vo.logistics.LogisticsAddressVo;
import com.suning.sawp.vo.logistics.LogisticsRequest;
import com.suning.sawp.vo.logistics.LogisticsStatusVo;
import com.suning.sawp.vo.logistics.LogisticsVo;
import com.suning.sawp.vo.logistics.SiteInfoVo;

@Service
public class LogisticsServiceImpl implements LogisticsService {

    private static final Logger LOGGER = LoggerFactory.getLogger(LogisticsServiceImpl.class);

    private static final String OPERATE_TPYE = "A";

    private static final String ORI_SYSTEM = "SNSAWP";

    /**
     * 自营物流esb
     */
    private LogisticsESBService logisticsESBService;

    /**
     * c店物流查询
     */
    private CStoreLogisticsESBService cStoreLogisticsESBService;

    /**
     * c店物流查询
     */
    @Autowired
    private OmsOrderDetailService omsOrderDetailService;

    public LogisticsESBService getLogisticsESBService() {
        return logisticsESBService;
    }

    @EsbEIHttpWired
    public void setLogisticsESBService(LogisticsESBService logisticsESBService) {
        this.logisticsESBService = logisticsESBService;
    }

    @Override
    public LogisticsVo queryLogisticsByPosOrderAndStoreCode(String posOrder, String storeCode) {
        LogisticsQueryReq req = new LogisticsQueryReq.Builder().operateType(OPERATE_TPYE).oriSystem(ORI_SYSTEM)
                .posOrder(posOrder).storeCode(storeCode).create();
        MbfResponse resp = null;
        LogisticsQueryResp qresp = null;
        resp = logisticsESBService.queryLogisticsDetails(req);
        if (null != resp && resp.isSucceed()) {
            qresp = (LogisticsQueryResp) resp.getOutput().getMbfBody(LogisticsQueryResp.class);
        }

        return tranLogisticsDto2LogisticsVo(tranLogisticsQueryResp2LogisticsDto(qresp));
    }

    private LogisticsDto tranLogisticsQueryResp2LogisticsDto(LogisticsQueryResp qresp) {
        LogisticsDto result = new LogisticsDto();
        if (null == qresp) {
            return result;
        }
        result.setHopeArrivalTime(parseDateFromString(qresp.getHopeArrivalTime()));
        result.setEstimateOutTime(parseDateFromString(qresp.getEstimateOutTime()));
        result.setSrvOmsItemId(qresp.getSrvOmsItemId());
        if (null != qresp.getLogisticsDetails() && !qresp.getLogisticsDetails().isEmpty()) {
            List<LogisticsDetailDto> logisticsDetails = Lists.newArrayList();
            for (LogisticsDetail logisticsDetail : qresp.getLogisticsDetails()) {
                if (null != logisticsDetail) {
                    logisticsDetails.add(tranlogisticsDetail2LogisticsDetailDto(logisticsDetail));
                }
            }
            result.setLogisticsDetails(logisticsDetails);
        }
        return result;
    }

    private LogisticsDetailDto tranlogisticsDetail2LogisticsDetailDto(LogisticsDetail logisticsDetail) {
        LogisticsDetailDto result = new LogisticsDetailDto();
        if (null != logisticsDetail) {
            result.setOrderItemId(logisticsDetail.getOrderItemId());
            result.setOperateTime(parseDateFromString(logisticsDetail.getOperateTime()));
            result.setOrderCategory(logisticsDetail.getOrderCategory());
            result.setOperateTypeCode(logisticsDetail.getOperateTypeCode());
            result.setCurrentSite(logisticsDetail.getCurrentSite());
            result.setNextSite(logisticsDetail.getNextSite());
            result.setOperator(logisticsDetail.getOperator());
            result.setPhoneNo(logisticsDetail.getPhoneNo());
            result.setCheckCode(logisticsDetail.getCheckCode());
            result.setExpressCode(logisticsDetail.getExpressCode());
            result.setExpressCompany(logisticsDetail.getExpressCompany());
            result.setSiteProperty(logisticsDetail.getSiteProperty());
            result.setCurrentSiteCode(logisticsDetail.getCurrentSiteCode());
            result.setDeliveryman(logisticsDetail.getDeliveryman());
            result.setReason(logisticsDetail.getReason());
        }
        return result;
    }

    private Date parseDateFromString(String time) {
        return DateUtils.getDateByStr(time, DateUtils.YYYYMMDDHHMMSS_PATTERN);
    }

    /**
     * @return the cStoreLogisticsESBService
     */
    public CStoreLogisticsESBService getcStoreLogisticsESBService() {
        return cStoreLogisticsESBService;
    }

    /**
     * @param cStoreLogisticsESBService the cStoreLogisticsESBService to set
     */
    @EsbEIHttpWired
    public void setcStoreLogisticsESBService(CStoreLogisticsESBService cStoreLogisticsESBService) {
        this.cStoreLogisticsESBService = cStoreLogisticsESBService;
    }

    @Override
    public CStoreLogisticsQueryResp queryCStoreLogistics(List<String> orderItemNos) {
        MbfResponse resp = null;
        CStoreLogisticsQueryResp qresp = null;

        List<CStoreLogisticsQueryDetail> cStoreLogisticsQueryDetails = Lists.transform(orderItemNos,
                new Function<String, CStoreLogisticsQueryDetail>() {
                    @Override
                    public CStoreLogisticsQueryDetail apply(String orderItemNo) {
                        CStoreLogisticsQueryDetail temp = new CStoreLogisticsQueryDetail();
                        temp.setOmsItemNo(orderItemNo);
                        return temp;
                    }
                });
        CStoreLogisticsQueryReq req = new CStoreLogisticsQueryReq();
        req.setcStoreLogisticsQueryDetails(Lists.newArrayList(cStoreLogisticsQueryDetails));
        resp = cStoreLogisticsESBService.queryLogisticsDetails(req);
        if (null != resp && resp.isSucceed()) {
            qresp = (CStoreLogisticsQueryResp) resp.getOutput().getMbfBody(CStoreLogisticsQueryResp.class);
        }
        return qresp;
    }

    @Override
    public LogisticsQueryResp querySelfSupportLogistics(String orderItemNo) {
        LogisticsQueryReq req = new LogisticsQueryReq.Builder().operateType(OPERATE_TPYE).oriSystem(ORI_SYSTEM)
                .orderItemId(orderItemNo).create();
        MbfResponse resp = null;
        LogisticsQueryResp qresp = null;
        resp = logisticsESBService.queryLogisticsDetails(req);
        if (null != resp && resp.isSucceed()) {
            qresp = (LogisticsQueryResp) resp.getOutput().getMbfBody(LogisticsQueryResp.class);
        }
        return qresp;
    }

    @Override
    public LogisticsVo queryLogistics(LogisticsRequest logisticsRequest) {

        LogisticsVo logisticsVo;
        String type = logisticsRequest.getType();
        // 查询订单详情获取收货地址相关信息
        LogisticsAddressVo addressVo = findAddressInfo(logisticsRequest);
        // 物流信息查询
        if (type.equals(LogisticsRequest.TYPE_SELFSUPPORT)) {
            // 自营物流查询
            LogisticsQueryResp selfSupportLogistics = querySelfSupportLogistics(logisticsRequest.getOmsItemNo());
            logisticsVo = tranLogisticsDto2LogisticsVo(tranLogisticsQueryResp2LogisticsDto(selfSupportLogistics));
            logisticsVo.setAddressInfo(addressVo);
            logisticsVo.setStatusInfo(findSelfSupportStatusInfo(selfSupportLogistics));
        } else {
            // C店物流查询
            CStoreLogisticsQueryResp cStoreLogisticsQueryResp = queryCStoreLogistics(
                    Lists.newArrayList(logisticsRequest.getOmsItemNo()));
            logisticsVo = transCStoreLogisticsQueryResp2LogisticsVo(cStoreLogisticsQueryResp);
            logisticsVo.setAddressInfo(addressVo);
        }
        return logisticsVo;
    }

    /**
     * 
     * 功能描述: <br>
     * 封装c店物流信息
     *
     * @param cStoreLogisticsQueryResp
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private LogisticsVo transCStoreLogisticsQueryResp2LogisticsVo(CStoreLogisticsQueryResp cStoreLogisticsQueryResp) {
        LogisticsVo logisticsVo = new LogisticsVo();
        // 物流状态信息
        LogisticsStatusVo logisticsStatusVo = new LogisticsStatusVo();
        // 物流站点描述信息
        List<SiteInfoVo> siteInfos = Lists.newArrayList();
        // 需要处理的物流信息
        List<CStoreLogisticsDetail> cStoreLogisticsDetails = filterCStoreLogisticsDetailByStatus(
                cStoreLogisticsQueryResp);
        if (CollectionUtils.isNotEmpty(cStoreLogisticsDetails)) {
            // 物流信息按操作时间降序,时间格式20100908162236
            Collections.sort(cStoreLogisticsDetails, new Comparator<CStoreLogisticsDetail>() {
                @Override
                public int compare(CStoreLogisticsDetail o1, CStoreLogisticsDetail o2) {
                    return o2.getOperateTime().compareTo(o1.getOperateTime());
                }
            });
            // 物流状态编码信息
            List<String> oprCodes = Lists.newArrayList();
            // c000物流状态信息,用于获取物流公司单号和物流单号
            CStoreLogisticsDetail c000Detail = new CStoreLogisticsDetail();
            // 生成物流站点描述
            for (CStoreLogisticsDetail cStoreLogisticsDetail : cStoreLogisticsDetails) {
                if (BaseContants.LogisticsContants.OPERATE_TYPE_CODE_C000
                        .equals(cStoreLogisticsDetail.getStatusCode())) {
                    c000Detail = cStoreLogisticsDetail;
                }
                oprCodes.add(cStoreLogisticsDetail.getStatusCode());
                SiteInfoVo siteInfoVo = new SiteInfoVo();
                siteInfoVo.setOperateTime(DateUtils.getDateStrByFormat(
                        parseDateFromString(cStoreLogisticsDetail.getOperateTime()), DateUtils.DEFAULT_TIME_PATTERN));
                siteInfoVo.setSiteDesc(
                        BaseContants.LogisticsContants.CSTORE_STATUS_MAP.get(cStoreLogisticsDetail.getStatusCode()));
                siteInfoVo.setPhoneNo(null == cStoreLogisticsDetail.getPhoneNum() ? StringUtils.EMPTY
                        : cStoreLogisticsDetail.getPhoneNum());
                siteInfos.add(siteInfoVo);
            }
            // 设置物流公司名
            logisticsStatusVo.setCompanyName(
                    null == c000Detail.getExpressCompany() ? StringUtils.EMPTY : c000Detail.getExpressCompany());
            // 设置快递单号
            logisticsStatusVo.setExpressNo(
                    null == c000Detail.getExpressCode() ? StringUtils.EMPTY : c000Detail.getExpressCode());
            // 设置物流状态
            if (oprCodes.contains(BaseContants.LogisticsContants.OPERATE_TYPE_CODE_C015)) {
                logisticsStatusVo.setStatusDesc(LogisticsStatusVo.STATUS_YWC);
            } else if (oprCodes.contains(BaseContants.LogisticsContants.OPERATE_TYPE_CODE_C010)) {
                logisticsStatusVo.setStatusDesc(LogisticsStatusVo.STATUS_YQS);
            } else {
                logisticsStatusVo.setStatusDesc(LogisticsStatusVo.STATUS_PSZ);
            }

        } else {
            logisticsStatusVo.setCompanyName(LogisticsStatusVo.DEFAULT_STATUSINFO);
            logisticsStatusVo.setStatusDesc(LogisticsStatusVo.DEFAULT_STATUSINFO);
            logisticsStatusVo.setExpressNo(LogisticsStatusVo.DEFAULT_STATUSINFO);
        }

        logisticsVo.setSiteInfos(siteInfos);
        logisticsVo.setStatusInfo(logisticsStatusVo);

        return logisticsVo;

    }

    /**
     * 
     * 功能描述: <br>
     * 过滤出c店需要解析的物流信息
     *
     * @param cStoreLogisticsQueryResp
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private List<CStoreLogisticsDetail> filterCStoreLogisticsDetailByStatus(
            CStoreLogisticsQueryResp cStoreLogisticsQueryResp) {
        List<CStoreLogisticsDetail> filterCStoreLogisticsDetails = Lists.newArrayList();
        if (null != cStoreLogisticsQueryResp
                && CollectionUtils.isNotEmpty(cStoreLogisticsQueryResp.getOrderDetailReturns())) {
            List<CStoreLogisticsDetail> cStoreLogisticsDetails = cStoreLogisticsQueryResp.getOrderDetailReturns();
            // 需要解析的物流状态集
            final Set<String> statusSet = BaseContants.LogisticsContants.CSTORE_STATUS_MAP.keySet();
            filterCStoreLogisticsDetails = Lists.newArrayList(FluentIterable.from(cStoreLogisticsDetails)
                    .filter(new com.google.common.base.Predicate<CStoreLogisticsDetail>() {
                        @Override
                        public boolean apply(CStoreLogisticsDetail cStoreLogisticsDetail) {
                            return statusSet.contains(cStoreLogisticsDetail.getStatusCode());
                        }
                    }));
        }
        return filterCStoreLogisticsDetails;
    }

    /**
     * 
     * 功能描述: <br>
     * 
     *
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private LogisticsStatusVo findSelfSupportStatusInfo(LogisticsQueryResp selfSupportLogistics) {
        LogisticsStatusVo logisticsStatusVo = new LogisticsStatusVo();
        if (null != selfSupportLogistics && CollectionUtils.isNotEmpty(selfSupportLogistics.getLogisticsDetails())) {
            logisticsStatusVo.setCompanyName(LogisticsStatusVo.SELFSUPPORT_COMPANYNAME);
            List<LogisticsDetail> details = selfSupportLogistics.getLogisticsDetails();
            List<String> oprCodes = Lists.transform(details, new Function<LogisticsDetail, String>() {
                @Override
                public String apply(LogisticsDetail input) {
                    return input.getOperateTypeCode();
                }
            });
            if (oprCodes.contains(String.valueOf(BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1101))) {
                logisticsStatusVo.setStatusDesc(LogisticsStatusVo.STATUS_YWC);
            } else {
                logisticsStatusVo.setStatusDesc(LogisticsStatusVo.STATUS_PSZ);
            }

        } else {
            logisticsStatusVo.setCompanyName(LogisticsStatusVo.DEFAULT_STATUSINFO);
            logisticsStatusVo.setStatusDesc(LogisticsStatusVo.DEFAULT_STATUSINFO);
        }
        return logisticsStatusVo;
    }

    /**
     * 
     * 功能描述: <br>
     * 获取收货人地址信息，脱敏
     *
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private LogisticsAddressVo findAddressInfo(final LogisticsRequest logisticsRequest) {
        OmsOrderDetailResp orderDetailResp = omsOrderDetailService.queryOrderDetails(
                Lists.newArrayList(logisticsRequest.getOmsOrderNo()), logisticsRequest.getMemberNo());
        if (null == orderDetailResp || CollectionUtils.isEmpty(orderDetailResp.getOrderList())) {
            throw new IllegalStateException("订单详情不存在");
        }
        OmsOrderList omsOrderDetail = orderDetailResp.getOrderList().get(0);
        String receiverName = omsOrderDetail.getName();
        String receiverMobile = omsOrderDetail.getMobilePhoneNum();
        String address = StringUtils.EMPTY;
        List<OmsOrderbodyList> omsOrderbodyLists = omsOrderDetail.getOrderbodyLists();
        if (CollectionUtils.isNotEmpty(omsOrderbodyLists)) {
            // 获取匹配的行项目详情
            OmsOrderbodyList itemDetail = (OmsOrderbodyList) CollectionUtils.find(omsOrderbodyLists,
                    new org.apache.commons.collections.Predicate() {
                        @Override
                        public boolean evaluate(Object object) {
                            return logisticsRequest.getOmsItemNo().equals(((OmsOrderbodyList) object).getOrderItemId());
                        }
                    });
            if (null != itemDetail) {
                address = itemDetail.getDeliveryAddrMain();
            }
        }
        LogisticsAddressVo addressVo = new LogisticsAddressVo();
        // 手机号,姓名，地址脱敏
        addressVo.setAddress(DJStringUtils.desensitiseOmsAddress(address));
        addressVo.setReceiverMobile(DJStringUtils.desensitiseMobile(receiverMobile));
        addressVo.setReceiverName(DJStringUtils.desensitiseName(receiverName));
        return addressVo;
    }

    private LogisticsVo tranLogisticsDto2LogisticsVo(LogisticsDto logisticsDto) {
        LogisticsVo logisticsVo = new LogisticsVo();
        if (null == logisticsDto) {
            return logisticsVo;
        }
        if (null != logisticsDto.getEstimateOutTime()) {
            logisticsVo.setEstimateOutTime(DateUtils.getDateStrByFormat(logisticsDto.getEstimateOutTime(),
                    DateUtils.ACCURATE_MINUTES_PATTERN));
        }
        if (null != logisticsDto.getHopeArrivalTime()) {
            logisticsVo.setHopeArrivalTime(DateUtils.getDateStrByFormat(logisticsDto.getHopeArrivalTime(),
                    DateUtils.ACCURATE_MINUTES_PATTERN));
        }
        List<SiteInfoVo> siteInfos = Lists.newArrayList();
        if (null != logisticsDto.getLogisticsDetails() && !logisticsDto.getLogisticsDetails().isEmpty()) {
            for (LogisticsDetailDto logisticsDetailDto : logisticsDto.getLogisticsDetails()) {
                String siteDesc = converterSiteDescFrom(logisticsDetailDto);
                if (null != logisticsDetailDto && StringUtils.isNotBlank(siteDesc)) {
                    SiteInfoVo siteInfoVo = new SiteInfoVo();
                    siteInfoVo.setPhoneNo(logisticsDetailDto.getPhoneNo());
                    siteInfoVo.setOperateTime(null != logisticsDetailDto.getOperateTime() ? DateUtils.getDateStrByFormat(logisticsDetailDto.getOperateTime(),
                            DateUtils.DEFAULT_TIME_PATTERN) : null);
                    siteInfoVo.setSiteDesc(siteDesc);
                    siteInfos.add(siteInfoVo);
                }
            }
        }
        logisticsVo.setSiteInfos(siteInfoSortDESCByOperateTime(siteInfos));
        
        return logisticsVo;
    }

    /**
     * 
     * 功能描述: <br>
     * 安装物流操作实际降序排列
     *
     * @param siteInfos
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private List<SiteInfoVo> siteInfoSortDESCByOperateTime(List<SiteInfoVo> siteInfos) {
        if (CollectionUtils.isNotEmpty(siteInfos)) {
            Ordering<SiteInfoVo> ord = new Ordering<SiteInfoVo>() {

                @Override
                public int compare(SiteInfoVo left, SiteInfoVo right) {
                    return ComparisonChain.start().compare(right.getOperateTime(), left.getOperateTime()).result();
                }
            };
            return ord.immutableSortedCopy(siteInfos);
        }
        return Lists.newArrayList();
    }

    private String converterSiteDescFrom(LogisticsDetailDto logisticsDetailDto) {
        String result = "";
        if (null != logisticsDetailDto) {
            int key = 0;
            try {
                key = Integer.parseInt(logisticsDetailDto.getOperateTypeCode());
            } catch (NumberFormatException e) {
                LOGGER.error("parseInt is fail,OperateTypeCode= " + logisticsDetailDto.getOperateTypeCode(), e);
            }
            switch (key) {
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1010:
                    result = String.format("发货清单已打印，%s准备出库", logisticsDetailDto.getCurrentSite());
                    break;
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1030:
                    result = "订单已完成拣货";
                    break;
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1070:
                    result = getLogisticsArrive(logisticsDetailDto);
                    break;
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1090:
                    result = getLogisticsDelivery(logisticsDetailDto);
                    break;
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1020:
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1080:
                    if (BaseContants.LogisticsContants.SITE_PROPERTY_X.equals(logisticsDetailDto.getSiteProperty())) {
                        result = String.format("已安排送货，快递员%s:%s", logisticsDetailDto.getOperator(),
                                logisticsDetailDto.getPhoneNo());
                    }
                    break;
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1101:
                    result = "送货服务已完成";
                    break;
                case BaseContants.LogisticsContants.OPERATE_TYPE_CODE_1102:
                    result = "送货服务已改期， 4008-365-365";
                    break;

                default:
                    LOGGER.warn("converterSiteDescFrom is fail !,logisticsDetailDto={}", logisticsDetailDto);
                    break;
            }
        }

        return result;
    }
    
    /**
     * 配送中物流
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param logisticsDetailDto
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getLogisticsArrive(LogisticsDetailDto logisticsDetailDto) {
        if (BaseContants.LogisticsContants.SITE_PROPERTY_2.equals(logisticsDetailDto.getSiteProperty())) {
            return String.format("订单商品已到达%s", logisticsDetailDto.getCurrentSite());
        } else if (BaseContants.LogisticsContants.SITE_PROPERTY_X
                .equals(logisticsDetailDto.getSiteProperty())) {
            return String.format("订单商品已到达%s,正在分配快递员配送", logisticsDetailDto.getCurrentSite());
        }
        return "";
    }

    /**
     * 出库物流
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param logisticsDetailDto
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getLogisticsDelivery(LogisticsDetailDto logisticsDetailDto) {
        if (BaseContants.LogisticsContants.SITE_PROPERTY_1.equals(logisticsDetailDto.getSiteProperty())) {
            return String.format("%s已发货出库，下一站%s", logisticsDetailDto.getCurrentSite(),
                    logisticsDetailDto.getNextSite());
        } else if (BaseContants.LogisticsContants.SITE_PROPERTY_2
                .equals(logisticsDetailDto.getSiteProperty())) {
            return String.format("订单商品已出%s，下一站%s", logisticsDetailDto.getCurrentSite(),
                    logisticsDetailDto.getNextSite());
        }
        return "";
    }
    @Override
    public LogisticsVo queryLogisticsForYxwt(LogisticsReq logisticsRequest) {
        LogisticsVo logisticsVo;
        String type = logisticsRequest.getType();
        type = StringUtils.isBlank(type)?"":type;
        // 查询订单详情获取收货地址相关信息
        // 物流信息查询
        if (type.equals(LogisticsRequest.TYPE_CSTORE)) {
            // C店物流查询
            CStoreLogisticsQueryResp cStoreLogisticsQueryResp = queryCStoreLogistics(
                    Lists.newArrayList(logisticsRequest.getOmsItemNo()));
            logisticsVo = transCStoreLogisticsQueryResp2LogisticsVo(cStoreLogisticsQueryResp);
        } else {
            // 自营物流查询
            LogisticsQueryResp selfSupportLogistics = querySelfSupportLogistics(logisticsRequest.getOmsItemNo());
            logisticsVo = tranLogisticsDto2LogisticsVo(tranLogisticsQueryResp2LogisticsDto(selfSupportLogistics));
            logisticsVo.setStatusInfo(findSelfSupportStatusInfo(selfSupportLogistics));
        }
        return logisticsVo;
    }
}
